<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>解密测试工具</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.1.0/jsencrypt.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="./encrypt/crypto.js"></script>
</head>
<style>
    .form {
        margin-bottom: 20px;
    }
    .form span{
        width: 140px;
        display: inline-block;
    }
</style>
<body>
    <div id="app">
        <div class="form">
            <span>原始消息：</span>
            <input type="text" v-model="message">
            <button @click="RC4MSG">RC4加密</button>
        </div>
        <div class="form">
            <span>RC4密钥：</span>
            <textarea rows="5" cols="65" v-model="RC4KEY"></textarea>
        </div>
        <div class="form">
            <span>RC4加密消息：</span>
            <textarea rows="5" cols="65"  v-model="RC4MESSAGE"></textarea>
            <button @click="MSG4RC4">RC4解密</button>
        </div>
        <div class="form">
            <span>RSA加密后RC4密钥：</span>
            <textarea rows="5" cols="65" v-model="RSARC4KEY"></textarea>
        </div>
        <div class="form">
            <span>RSA公钥：</span>
            <textarea rows="5" cols="65" v-model="RSAPUBLICKKEY"></textarea>
            <button @click="RSAEncryptRC4KEY">RSA加密RC4密钥</button>
        </div>
        <div class="form">
            <span>RSA私钥：</span>
            <textarea rows="5" cols="65" v-model="RSAPRAVATEKEY"></textarea>
            <button @click="RSADecryptRC4KEY">RSA解密RC4密钥</button>
        </div>
    </div>
</body>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            message: 'hello',
            RC4KEY: '317043',
            RC4MESSAGE: 'U2FsdGVkX18U+6bYuTTomlGA9X08Dg==',
            RSARC4KEY: 'MM0kZOdFh8FtNN8Il1A+D8ap3mx72042eTBhu4OYF4TzlunghSZFCoorbEQUFO4cZr9NFu6iUpRqxFcXZUQd0g==',
            RSAPUBLICKKEY:`-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAL338nIPEPkRvfnk6ufQwgkmDkG2rLsK
gyNXFmEctGYEqkGrs0YAJOOPcQDup+lx8YSRKkj9JM+WGvAdoNkmZnECAwEAAQ==
-----END PUBLIC KEY-----`,
            RSAPRAVATEKEY: `-----BEGIN PRIVATE KEY-----
MIIBVgIBADANBgkqhkiG9w0BAQEFAASCAUAwggE8AgEAAkEAvffycg8Q+RG9+eTq
59DCCSYOQbasuwqDI1cWYRy0ZgSqQauzRgAk449xAO6n6XHxhJEqSP0kz5Ya8B2g
2SZmcQIDAQABAkArRtsSpOAG/cW7sizZlrM9hk/lJIqBKcnqOSK+CN4IB06hmLbH
VwktHvUvGKE+C7LNc6hMA4+gr6W9DFE2BfgBAiEA/KWZil3Zk/4s078GHwOoIwbR
TYg+b1FSHKzwt+Qgx0ECIQDAfWO8vp/jGDSn6/jr0oiZsalnizcnRj4fLA+M6GqD
MQIhANdtNTEAuWgx0XN0bPnBGntTcuETjXlJ9CQzasbCpRiBAiEAus/2oBORMOEp
GV+WsageEqut8WPXHzK4z5//Z42Y8cECIQCEsPnn7NUL291P655upkdIVhBlPaNF
jPcdk30SIeaTTQ==
-----END PRIVATE KEY-----`
        },
        methods: {
            Encrypt (data, key) {
                let encrypted = Encrypto.RC4.encrypt(data, key, {
                    mode: Encrypto.mode.CTR,
                }).toString();
                return encrypted
            },
            Decrypt  (data, key) {
                let decrypted = Encrypto.RC4.decrypt(data, key, {
                    mode: Encrypto.mode.CTR,
                // });
                }).toString(Encrypto.enc.Utf8);
                return decrypted
            },
            DecryptRsa  (data, key) {
                const decrypt = new JSEncrypt();
                decrypt.setPrivateKey(key);
                const decrypted = decrypt.decrypt(data);
                return decrypted
            },
            EncryptRsa  (data, key) {
                const encrypt = new JSEncrypt();
                encrypt.setPublicKey(key);
                const encrypted = encrypt.encrypt(data);
                return encrypted
            },
            RC4MSG(){
                let encrypt = this.Encrypt(this.message, this.RC4KEY);
                this.RC4MESSAGE = encrypt
            },
            MSG4RC4() {
                let decrypt = this.Decrypt(this.RC4MESSAGE, this.RC4KEY);
                this.message = decrypt;
            },
            RSAEncryptRC4KEY () {
                let encrypt = this.EncryptRsa(this.RC4KEY, this.RSAPUBLICKKEY)
                this.RSARC4KEY = encrypt
            },
            RSADecryptRC4KEY () {
                let decrypt = this.DecryptRsa(this.RSARC4KEY, this.RSAPRAVATEKEY)
                this.RC4KEY = decrypt
            }
        }
    })
</script>
</html>